interface Production<out T> {
    fun product(): T
}

interface Consumer<in T> {
    fun consume(item: T)
}

interface ProductionConsumer<T> {
    fun product(): T
    fun consume(item: T)
}

open class Food
open class FastFood : Food()
class Burger : FastFood()

class FoodStore : Production<Food> {
    override fun product(): Food {
        println("Product food.")
        return Food()
    }
}

class FastFoodStore : Production<FastFood> {
    override fun product(): FastFood {
        println("Product fastFood.")
        return FastFood()
    }
}

class BurgerStore : Production<Burger> {
    override fun product(): Burger {
        println("product burger.")
        return Burger()
    }
}

class EveryBody:Consumer<Food> {
    override fun consume(item: Food) {
       println("eat food")
    }
}

class ModernPeople:Consumer<FastFood>{
    override fun consume(item: FastFood) {
        println("ead food.")
    }
}

class American:Consumer<Burger> {
    override fun consume(item: Burger) {
        println("eat burger")
    }

}

fun main() {
    //out子类泛型对象可以赋值给父类泛型对象
    val foodStore: Production<Food> = FoodStore()
    val fastFoodStore: Production<Food> = FastFoodStore()

    val consumer1: Consumer<Burger> = EveryBody()
    val consumer2: Consumer<Burger> = ModernPeople()
    consumer2.consume(Burger())
    val consumer3: Consumer<Burger> = American()
}